﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using UWP.Douban.Api;
using UWP.Douban.Models;
using UWP.Douban.SampleData;
using Windows.UI.Xaml.Navigation;

namespace UWP.Douban.Mvvm
{
    public class TopicCommentVm:BaseVm
    {
        private Topic _currentTopic;
        public TopicCommentVm()
        {
            Comments = new ObservableCollection<Comment>();

            GoRelyCommentCommand = new RelayCommand(GoRelyComment);
        }

        public ICommand GoRelyCommentCommand { get; set; }

        public ObservableCollection<Comment> Comments { get; set; }

        private void GoRelyComment()
        {
            Navigate(typeof(Views.ReplyCommentPage), _currentTopic);
        }

        public async override void OnNavigatedTo(NavigationEventArgs e)
        {
            //var comments = await SampleDataUtil.GetComments();
            _currentTopic = e.Parameter as Topic;

            var comments = await GroupApi.GpSearchTopicComments(_currentTopic.Id);

            Comments.Clear();
            if (comments != null)
                foreach (var item in comments)
                {
                    Comments.Add(item);
                }

            base.OnNavigatedTo(e);
        }
    }
}
